﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using MaxStudio.Concrete.DBUtility;
using MaxStudio.Concrete.Server.Dao;
using MaxStudio.Concrete.Server.Interface;

namespace MaxStudio.Concrete.Server.Service
{
    public class TransportService : ServiceHandle, ITransport
    {
        #region ITransport Members

        public OperationResult<List<tb_Transport>> GetAllTransport()
        {
            OperationResult<List<tb_Transport>> result = new OperationResult<List<tb_Transport>>();
            ConcreteDaoDataContext dataContext = getDateContext();
            List<tb_Transport> list = new List<tb_Transport>();
            try
            {
                list = dataContext.GetAllTransport();
                if (list == null)
                {
                    result.errorMessageKey = "Error";
                }
                else
                {
                    result.obj = list;
                    result.operationSuccess = true;
                }
            }
            catch (Exception ex)
            {
                result.exceptionString = DlHelper.ExceptionString(ex);

            }
            return result;
        }

        public OperationResult<List<tb_Transport>> GetTransportByTransportType(int transportType)
        {
            OperationResult<List<tb_Transport>> result = new OperationResult<List<tb_Transport>>();
            ConcreteDaoDataContext dataContext = getDateContext();
            List<tb_Transport> list = new List<tb_Transport>();
            try
            {
                list = dataContext.GetTransportByTransportType(transportType);
                if (list == null)
                {
                    result.errorMessageKey = "Error";
                }
                else
                {
                    result.obj = list;
                    result.operationSuccess = true;
                }
            }
            catch (Exception ex)
            {
                result.exceptionString = DlHelper.ExceptionString(ex);

            }
            return result;
        }

        public OperationResult<List<tb_Transport>> GetTransportByReferId(int referId)
        {
            OperationResult<List<tb_Transport>> result = new OperationResult<List<tb_Transport>>();
            ConcreteDaoDataContext dataContext = getDateContext();
            List<tb_Transport> list = new List<tb_Transport>();
            try
            {
                list = dataContext.GetTransportByReferId(referId);
                if (list == null)
                {
                    result.errorMessageKey = "Error";
                }
                else
                {
                    result.obj = list;
                    result.operationSuccess = true;
                }
            }
            catch (Exception ex)
            {
                result.exceptionString = DlHelper.ExceptionString(ex);

            }
            return result;
        }

        public OperationResult<List<tb_Transport>> GetTransportByReferId(int referId, int transportType)
        {
            OperationResult<List<tb_Transport>> result = new OperationResult<List<tb_Transport>>();
            ConcreteDaoDataContext dataContext = getDateContext();
            List<tb_Transport> list = new List<tb_Transport>();
            try
            {
                list = dataContext.GetTransportByReferId(referId, transportType);
                if (list == null)
                {
                    result.errorMessageKey = "Error";
                }
                else
                {
                    result.obj = list;
                    result.operationSuccess = true;
                }
            }
            catch (Exception ex)
            {
                result.exceptionString = DlHelper.ExceptionString(ex);

            }
            return result;
        }

        public OperationResult<tb_Transport> GetTransportById(int id)
        {
            OperationResult<tb_Transport> result = new OperationResult<tb_Transport>();
            ConcreteDaoDataContext dataContext = getDateContext();
            tb_Transport transport;
            try
            {
                transport = dataContext.GetTransportById(id);
                if (transport == null)
                {
                    result.errorMessageKey = "Error";
                }
                else
                {
                    result.obj = transport;
                    result.operationSuccess = true;
                }
            }
            catch (Exception ex)
            {
                result.exceptionString = DlHelper.ExceptionString(ex);

            }
            return result;
        }

        public OperationResult<tb_Transport> CreateTransport(tb_Transport entity)
        {
            OperationResult<tb_Transport> result = new OperationResult<tb_Transport>();
            ConcreteDaoDataContext dataContext = getDateContext();

            try
            {
                dataContext.CreateTransport(entity);
                dataContext.SubmitChanges();
                result.obj = entity;
                result.operationSuccess = true;
            }
            catch (Exception ex)
            {
                result.exceptionString = DlHelper.ExceptionString(ex);
            }

            return result;
        }

        public OperationResult<tb_Transport> ModifyTransport(tb_Transport entity)
        {
            OperationResult<tb_Transport> result = new OperationResult<tb_Transport>();
            ConcreteDaoDataContext dataContext = getDateContext();

            try
            {
                dataContext.ModifyTransport(entity);
                dataContext.SubmitChanges();
                result.obj = entity;
                result.operationSuccess = true;
            }
            catch (Exception ex)
            {
                result.exceptionString = DlHelper.ExceptionString(ex);
            }

            return result;
        }

        public OperationResult<tb_Transport> DeleteTransport(tb_Transport entity)
        {
            OperationResult<tb_Transport> result = new OperationResult<tb_Transport>();
            ConcreteDaoDataContext dataContext = getDateContext();

            try
            {
                dataContext.DeleteTransport(entity);
                dataContext.SubmitChanges();
                result.obj = entity;
                result.operationSuccess = true;
            }
            catch (Exception ex)
            {
                result.exceptionString = DlHelper.ExceptionString(ex);
            }

            return result;
        }

        #endregion
    }
}
